<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 用户输入一个整数n：
    求1! + 2! + 3! + 4! + …… + n!的和
     叹号表示阶乘，如4! = 1 * 2 * 3 * 4 -->
    <script type="text/javascript">
        var m = parseInt(prompt('请输入任意整数', 6));
        var sum = 0;

        for (var i = 1; i <= m; i++) {
            function num(n) { //封装单个数的阶乘
                if (n == 1) {
                    return 1
                } else {
                    return n * num(n - 1)
                }
            }
            sum += num(i)
        }
        alert(m + '的阶乘和为:' + sum)
    </script>
</body>

</html>